﻿package com.wandian.util
{
	import com.greensock.TweenLite;
	import com.wandian.ApplicationFacade;
	import com.wandian.data.GameData;
	import com.wandian.model.vo.FriendVo;
	import com.wandian.util.scrollBar.ScrollBarMc;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.TextField;

    public class CLZListRank extends Object
    {
        private var _global:GameData;
        private var _mcParent:Sprite;
        private var _ClassName:String;
        private var _prevBtn:MovieClip;
        private var _nextBtn:MovieClip;
        private var _fristBtn:MovieClip;
        private var _endBtn:MovieClip;
        private var _mcW:int = 70;
        private const INTERVAL:int = 18;
        private const pageNum:int = 9;
        private var _maskMc:Sprite;
        private var _arrMcList:Array;
        private var _nCurInitMc:int;
        private var _nLen:int;

        public function CLZListRank(param1:Sprite, param2:String, param3:MovieClip, param4:MovieClip, param5:MovieClip, param6:MovieClip)
        {
            this._global = GameData.getInstance();
            this._mcParent = param1;
            this._ClassName = param2;
            this._prevBtn = param3;
            this._nextBtn = param4;
            this._fristBtn = param5;
            this._endBtn = param6;
            CLZButton.setButton(this._prevBtn);
            CLZButton.setButton(this._nextBtn);
            CLZButton.setButton(this._fristBtn);
            CLZButton.setButton(this._endBtn);
            this._prevBtn.addEventListener(MouseEvent.CLICK, this.prevHandler);
            this._nextBtn.addEventListener(MouseEvent.CLICK, this.nextHandler);
            this._fristBtn.addEventListener(MouseEvent.CLICK, this.fristHandler);
            this._endBtn.addEventListener(MouseEvent.CLICK, this.endHandler);
            this._maskMc = new Sprite();
            this._maskMc.graphics.beginFill(0);
            this._maskMc.graphics.lineStyle(1, 0);
            this._maskMc.graphics.drawRect(0, 0, this._mcW * this.pageNum + this.pageNum * this.INTERVAL - this.INTERVAL / 2, 200);
            this._maskMc.graphics.endFill();
            this._mcParent.parent.addChild(this._maskMc);
            this._maskMc.x = this._mcParent.x;
            this._maskMc.y = this._mcParent.y;
            this._mcParent.mask = this._maskMc;
            return;
        }

        private function prevHandler(event:MouseEvent) : void
        {
            this._nCurInitMc = this._nCurInitMc - this.pageNum;
            if (this._nCurInitMc <= 0)
            {
                this._nCurInitMc = 0;
            }
            this.showX(-this._arrMcList[this._nCurInitMc].x + this._maskMc.x);
            return;
        }

        private function nextHandler(event:MouseEvent) : void
        {
            this._nCurInitMc = this._nCurInitMc + this.pageNum;
            if (this._nCurInitMc >= this._nLen - this.pageNum)
            {
                this._nCurInitMc = this._nLen - this.pageNum;
            }
            this.showX(-this._arrMcList[this._nCurInitMc].x + this._maskMc.x);
            return;
        }

        private function fristHandler(event:MouseEvent) : void
        {
            this._nCurInitMc = 0;
            this.showX(-this._arrMcList[this._nCurInitMc].x + this._maskMc.x);
            return;
        }

        private function endHandler(event:MouseEvent) : void
        {
            this._nCurInitMc = this._nLen - this.pageNum;
            this.showX(-this._arrMcList[this._nCurInitMc].x + this._maskMc.x);
            return;
        }

        private function showX(param1:int) : void
        {
            trace(this._mcParent.x, this._maskMc.x);
            TweenLite.to(this._mcParent, 1.2, {x:param1});
            return;
        }

        public function setList(param1:Array, param2:int) : void
        {
			trace("[CLZListRank.setList break]");
			return;
            var mcClz:MovieClip = null;
            var _loc_6:FriendVo = null;
            GameData.removeNumChildre(this._mcParent);
            this._arrMcList = [];
            var total:* = param1.length;
            var index:int = 0;
            while (index < total)
            {
                
                mcClz = GameData.getMovieClip(this._ClassName);
                this._mcParent.addChild(mcClz);
                mcClz.x = this._mcW * index + index * this.INTERVAL;
                mcClz.num_txt.text = ((index + 1)).toString();
                if (param2 == 3)
                {
                    _loc_6 = param1[index] as FriendVo;
                    mcClz.name_txt.text = _loc_6.name;
                    mcClz.gold_txt.text = this._global.counstK(_loc_6.gold) + " ";
                    if (_loc_6.sex == 1)
                    {
                        CLZLoadIcon.addIcon(mcClz.pic, _loc_6.icon, 50, 50, 0, 0, "InitPicGirlIcon", false, false);
                    }
                    else
                    {
                        CLZLoadIcon.addIcon(mcClz.pic, _loc_6.icon, 50, 50, 0, 0, "InitPicBoyIcon", false, false);
                    }
                }
                else
                {
                    mcClz.name_txt.text = param1[index][2];
                    mcClz.gold_txt.text = this._global.counstK(param1[index][4]) + " ";
                    if (param1[index][3] == 1)
                    {
                        CLZLoadIcon.addIcon(mcClz.pic, param1[index][1], 50, 50, 0, 0, "InitPicGirlIcon", false, false);
                    }
                    else
                    {
                        CLZLoadIcon.addIcon(mcClz.pic, param1[index][1], 50, 50, 0, 0, "InitPicBoyIcon", false, false);
                    }
                }
                this._arrMcList.push(mcClz);
                index = index + 1;
            }
            if (total < this.pageNum)
            {
                index = total;
                while (index < this.pageNum)
                {
                    
                    mcClz = GameData.getMovieClip("AddFriend");
                    this._mcParent.addChild(mcClz);
                    mcClz.addEventListener(MouseEvent.CLICK, this.onInvitationFunc);
                    CLZButton.setButton(mcClz, GameData.tip["INVITATION_FRIEND"]);
                    mcClz.x = this._mcW * index + index * this.INTERVAL;
                    this._arrMcList.push(mcClz);
                    index = index + 1;
                }
            }
            this._nCurInitMc = 0;
            this._nLen = this._arrMcList.length;
            this.fristHandler(null);
            return;
        }

        private function onInvitationFunc(event:MouseEvent) : void
        {
//            JSFUN.shareInvitationFunc();
            return;
        }

    }
}
